<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>CORS</title>
</head>
<body>
        <h2 class="h2">CORS 跨域资源共享实现跨域</h2>
        <script>
            var xhr = new XMLHttpRequest();
            // vim /etc/hosts
            // 127.0.0.1 a.com
            xhr.open('GET','http://a.com:9090');
            xhr.send();
            xhr.onload = function (ev) {
                var html = '<p>request Success! result=' + this.responseText + '</p>';
                document.querySelector('.h2').insertAdjacentHTML('afterEnd',html);
            }
            xhr.onerror = function (ev) {
                var html = document.createElement('p');
                html.innerText = 'request error';
                document.querySelector('.h2').insertAdjacentHTML('afterEnd',html);
            }
        </script>
</body>
</html>